#! /usr/bin/env python
# -*- coding: utf8 -*-

# Alexandre Coster <acoster@rhrk.uni-kl.de>
# AG DBIS - Technische Universität Kaiserslautern

# mXML: Messy XML Generator
# This application generates a dirty (messy) XML file (with changes
# both on the values and the structure) based on a "clean" input

from zope.interface import Interface, Attribute
import re

if __name__ == "__main__":
    print "You shouldn't be running this file!"
    sys.exit()

def node_to_dictionary(node):
    """
    Converts an xXML algorithm configuration to a dictionary.
    """
    params = {}

    for i in node.findall("./parameters/*"):
        params[i.tag] = i.text.strip()

    return params

def parser(s):
    hasAlter = re.compile("(.*)\|(.*)")

    fineStuff  = []
    roughStuff = s.split('/')

    for i in roughStuff:
        if i == '':
            continue

        if hasAlter.match(i) != None:
            result = i.split("|")
            fineStuff.append([x.strip() for x in result])
        else:
            fineStuff.append(i.strip())

    return fineStuff

class IAlgorithm(Interface):
    algorithm_name = Attribute("""String containing the name to be used on the configuration file""")

    def __init__(node):
        """Algorithm constructor."""

    def __call__(node, parentMap, root):
        """Applies the algorithm to the selected node."""
